<?php
header("Content-type:text/html; charset=utf-8");
include 'UpFile.class.php';
include ("../conn.php");

$text = array("HTTP://WWW.XMTANGDA.COM","厦门唐达工贸有限公司"); //水印内容

$gctype = "ABOUT_US";
$gcid = "";
if(isset($_GET['cid'])){
	$gcid = $_GET['cid'];
}
$act = "";
if(isset($_GET['act'])){
	$act =$_GET['act'];
}

$opertype = "";
if(isset($_GET['opertype'])){
	$opertype = $_GET['opertype'];
}

if($act=="")$act = "create";//update
if($opertype=="") $opertype = "main";//file


//修改关于我们内容
if(isset($_POST['submit']) && $opertype=="main"){
	$sql = "update ".$databasepre."common set CMEMO='".mysql_real_escape_string($_POST['CMEMO'])."',CMEMO2='"
		.mysql_real_escape_string($_POST['CMEMO2'])
		."' where CSELFID=1 and CPARENTID=0 and CTYPE='".$gctype."'";
	//echo $sql;
	mysql_query($sql);
	echo "保存成功!<a href=admin_aboutus.php>返回</a>";exit;
}

//图片新增
if(isset($_POST['submit']) && $opertype=="file" && $act=="create"){
	
	if(@empty($_FILES["CCONTENT"]["name"])) 
	die("没有上传文件信息，请确认！<a href='?opertype=file'>返回</a>");

	$ctitle = trim(mysql_real_escape_string($_POST['CTITLE']));
	$cseq = intval($_POST['CSEQ']);

	$upFile= new UpFile(); //实例化类文件
	$photo = $upFile->upLoad("CCONTENT"); //上传的文件域

	$upFile->toFile = true;
	$upFile->saveBigImg($photo);
	$upFile->saveSmallImg($photo,320,240);

	//入库
	$sql =  "insert into ".$databasepre."common(CTYPE,CTITLE,CCONTENT,CSEQ,CPARENTID) values ('".$gctype."','".$ctitle."','".$photo."',".$cseq.",1) ";
	mysql_query($sql);
	echo "保存成功!<a href='?opertype=file'>返回</a>";exit;
}

//删除操作
if(isset($_GET['cid']) && $opertype=="file" && $act=="del")
{
	$selsql = "select CCONTENT from ".$databasepre."common where CTYPE='".$gctype."' and CID='".$gcid."'";
	$query = mysql_query($selsql);
	$row=mysql_fetch_array($query);

	@unlink("..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."original".DIRECTORY_SEPARATOR.$row['CCONTENT']);
	@unlink("..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."big".DIRECTORY_SEPARATOR.$row['CCONTENT']);
	@unlink("..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."small".DIRECTORY_SEPARATOR.$row['CCONTENT']);

	$delsql="delete from ".$databasepre."common where ctype='".$gctype."' and cid='".$gcid."'";
	mysql_query($delsql);
	echo "删除成功!<a href=?opertype=file>返回</a>";exit;
}
?>
<html><head>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #EEF2FB;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif">
		<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
		  <tr><td height="31"><div class="titlebt">常规管理</div></td></tr>
		</table>
	</td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9">
	<!-- 网页内容部分开始 -->


	<table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr><td height="13" valign="top">&nbsp;</td></tr>
	  <tr><td class="left_txt">当前位置：关于我们管理</td></tr>
	  <!-- 一根线 -->
	  <tr><td height="20"><table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"><tr><td></td></tr></table></td></tr>
	  <!-- 说明信息 -->
	  <tr><td><table width="100%" height="55" border="0" cellpadding="0" cellspacing="0"><tr>
				<td width="10%" height="55" valign="middle"><img src="images/title.gif" width="54" height="55"></td>
				<td width="90%" valign="top"><span class="left_txt2">在这里，您可以根据您的网站要求，修改设置网站的关于我们的内容！</span></td>
				</tr></table>
		</td>
	  </tr>
	  <tr><td>&nbsp;</td></tr>
	  <tr><td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
				  <tr>

				  		<td class="left_bt2" width=10% bgcolor="<?php echo $opertype=="main"?"#9999FF":"#C0C0C0" ?>" align=center>&nbsp;<a href="?opertype=main">内容管理</a></td>
				  		<td class="left_bt2" width=10% bgcolor="<?php echo $opertype=="file"?"#9999FF":"#C0C0C0" ?>" align=center><a href="?opertype=file">图片管理</a></td>
				  		<td class="left_bt2" width=70%>&nbsp;</td></tr>
				</table>
		</td>
      </tr>
	  <tr><td><table width="90%" border="0" cellspacing="10" cellpadding="0">
				<form method=POST action="" enctype="multipart/form-data">

				<?php
					if($opertype=="main") {
					//判断初始化关于我们是否已存在，否则需要新增 cselfid=1 cparentid=0 ctype=ABOUT_US
					$sql = "select CMEMO,CMEMO2 from ".$databasepre."common where ctype='".$gctype."' and cselfid=1 and cparentid=0";
					$query = mysql_query($sql);
					$row=mysql_fetch_array($query);
					if(!$row){
						$createSql = "insert into ".$databasepre."common(ctype,cmemo,cselfid,cparentid) values ('".$gctype."','About us',1,0)";
						mysql_query($createSql);

						$query = mysql_query($sql);
						$row=mysql_fetch_array($query);
					}
				?>

					<tr>
						<td height="30">英文：</td>
						<td align=left colspan=3>
						  <textarea name="CMEMO" rows="15" cols="70"><?php echo $row['CMEMO'] ?></textarea>
					  	</td>

						<td align=left></td>
					</tr>
					<tr>
						<td height="30">中文：</td>
						<td align=left colspan=3>
						  <textarea name="CMEMO2" rows="15" cols="70"><?php echo $row['CMEMO2'] ?></textarea>
					  	</td>

						<td align=left></td>
					</tr>
					<tr>
						<td height="30"></td>
						<td align=left colspan=3>
						  <input type="submit" name="submit" value=" 确 定 " />
					  	</td>
						<td align=left></td>
					</tr>
				<?php }else if($opertype=="file") { ?>

					<tr bgcolor="#f2f2f2">
						<th width="100" class="left_txt" align=left></th>
						<th width="200" height="30" class="left_txt2" align=left>名称</th>
						<th width="200" class="left_txt2" align=left>路径</th>
						<th width="100" class="left_txt2" align=left>排序[升序]</th>
						<th width="100" class="left_txt2" align=left>操作</th>
					</tr>
					<?php if($act=="create") { ?>
					<tr>
					<td height="30"></td>
					<td align=left><input type="text" name="CTITLE" value="" size="20" maxlength="40"/></td>
					<td align=left><input type="file" name="CCONTENT" value="" size="20" maxlength="40"/></td>
					<td align=left><input type="text" name="CSEQ" value="" size="5" maxlength="40"/></td>
					<td align=left><input type="submit" name="submit" value=" 新 增 " /></td>
					</tr>
					<?php
					}
					$tdstyle="";
					$tdi = 0;
					$sql="select * from ".$databasepre."common where CTYPE='".$gctype."' and CPARENTID=1 order by CSEQ asc,CID asc";
					$query=mysql_query($sql);
					while($prow=mysql_fetch_array($query))
					{
						$tdi = $tdi + 1;
						if($tdi%2 == 1) { $tdstyle = "f2f2f2"; }else{ $tdstyle = ""; }
						echo '<tr bgcolor='.$tdstyle.'>';
						echo '<td height="30"></td>';
						echo '<td align=left>'.$prow['CTITLE'].'</td>';
						echo '<td align=left><img src="../upload/small/'.$prow['CCONTENT'].'" border="0"></td>';
						echo '<td align=left>'.$prow['CSEQ'].'</td>';
						echo '<td align=left> <a href=?opertype=file&act=del&cid='.$prow['CID'].'> 删 除 </a></td>';
						echo '</tr>';
					}

				}
					?>




				</form>
			  </table>
			</td>
		</tr>



	 </table>






	<!-- 网页内容部分结束 -->
	</td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="bottom" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
    <td background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17"></td>
    <td valign="bottom" background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>
</body>
</html>
